<template>
    <div>
        <Form :label-width="120" inline>
            <Form-item label="行政区划：">
                <Ss01001Tag :bindData.sync="searchInfo.bindData"
                            :bindLevel.sync="searchInfo.bindLevel"
                >
                </Ss01001Tag>
            </Form-item>
            <Form-item label="姓名：">
                <Input style="width: 100px" v-model="searchInfo.fkrk0006"/>
            </Form-item>
            <Form-item label="证件号码：">
                <Input style="width: 160px" v-model="searchInfo.fkrk0008"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                     <Button type="primary" @click="createSS00013"><Icon
                             type="ios-add"/>新增</Button>
                     <Upload ref="upload" action="/api/ac/subsistence/ss00013Service/createImportExcel"
                             style="display: inline-block;"
                             :on-success="handleSuccess" :on-error="onError"
                             name="files">
                    <Button type="primary" icon="ios-cloud-upload-outline" class="button_item_left">导入</Button>
                </Upload>
                <Button type="primary" icon="ios-cloud-download-outline" @click="exportExcel" class="button_item_left">
                    导出
                </Button>
                <Button type="primary" icon="ios-cloud-download-outline" @click="exportTemplate"
                        class="button_item_left">
                    下载模版
                </Button>

                </span>
                <span style="float: right;">
                  <Button type="primary" @click="searchData(false)"><Icon
                          type="ios-search"/> 查询</Button>
                </span>
            </Row>
        </Form>
        <Modal v-model="modalShow" :title="title" :mask-closable="false" width="800">
            <Form :model="formItem" :label-width="100" ref="ruleValidate" :rules="ruleValidate" inline>
                <FormItem label="行政区划:" prop="fkrk0001">
                    <Ss01001Tag v-bind:disabled="disable"
                                style="width: 100%;"
                                :bindData.sync="formItem.bindData"
                                :bindLevel.sync="formItem.bindLevel"
                                :xq_value="sel_xqval"
                                :jd_value="sel_jdval"
                                :sq_value="sel_sqval"
                                :level="level"
                                :sq_disabled="sq_disabled"
                                :jd_disabled="jd_disabled"
                                :xq_disabled="xq_disabled"
                    ></Ss01001Tag>
                </FormItem>

                <FormItem label="姓名:" prop="fkrk0006">
                    <Input v-model="formItem.fkrk0006" v-bind:disabled="disable" placeholder="姓名"></Input>
                </FormItem>
                <FormItem label="性别:" prop="fkrk0007">
                    <Select v-model="formItem.fkrk0007" placeholder="性别" v-bind:disabled="disable" style="width: 164px">
                        <Option value="男">男</Option>
                        <Option value="女">女</Option>
                    </Select>
                </FormItem>
                <FormItem label="身份证号:" prop="fkrk0008">
                    <Input v-model="formItem.fkrk0008" v-bind:disabled="disable" placeholder="身份证号"></Input>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="info" v-if="type==='1' && type !== '3'" @click="addOk('ruleValidate')">添加</Button>
                <Button type="info" v-if="type==='2' && type !== '3'" @click="updateOk('ruleValidate')">保存</Button>
                <Button type="default" @click="closeModel">关闭</Button>
            </div>
        </Modal>

        <div class="table_div">
            <Table :columns="columns1" :data="data">
                <template slot-scope="{ row }" slot="action">
                    <Button type="info" size="small" style="margin-right: 5px" @click="updateModal(row)">编辑</Button>
                    <Button type="success" size="small" style="margin-right: 5px" @click="showModal(row)">详情</Button>
                    <Button type="error" size="small" style="margin-right: 5px" @click="remove(row)">删除</Button>
                </template>
            </Table>
            <Page :total="dataCount" :page-size="pageSize" @on-change="changePage" show-total class="paging"></Page>
        </div>


    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import Ss01001Tag from '@/components/system/ss01001-select'

    export default {
        mixins: [CommonMixin],
        components: {
            Ss01001Tag
        },
        data() {
            return {
                level: '3',
                xq_disabled: false,
                jd_disabled: false,
                sq_disabled: false,
                // xq_display: true,
                exportTemplateFileName: "扶贫人口模版",
                exportFileName: "扶贫人口信息表",
                url: {
                    list: "/api/ac/subsistence/ss00013Service/page",
                    exportTemplate: "/api/ac/subsistence/ss00013Service/exportTemplate",
                    exportExcel: "/api/ac/subsistence/ss00013Service/exportExcel",
                },
                ruleValidate: {
                    fkrk0006: [
                        {required: true, message: '姓名不能为空', trigger: 'blur'}
                    ],
                    fkrk0007: [
                        {required: true, message: '性别不能为空', trigger: 'blur'}
                    ],
                    fkrk0008: [
                        {required: true, message: '身份证不能为空', trigger: 'change'}
                    ],
                    // fkrk0009: [
                    //     { required: true,  message: '出生日期不能为空', trigger: 'change' }
                    // ]
                },
                type: '',
                title: '',
                sel_xqval: '',
                sel_jdval: '',
                sel_sqval: '',
                // sel_xqval:'210105000000',
                // sel_jdval:'210105014000',
                // sel_sqval:'210105014003',
                mode: true,
                statusLevel: '',
                disable: false,
                formItem: {
                    id: '',
                    fkrk0003: '',
                    fkrk0004: '',
                    fkrk0005: '',
                    fkrk0006: '',
                    fkrk0007: '',
                    fkrk0008: '',
                    fkrk0009: '',
                    bindData: '',
                    bindLevel: '',
                    bindSq: '',
                    bindJd: '',
                    bindXq: '',

                },
                searchInfo: {
                    bindData: '',
                    bindLevel: '',
                    fkrk0010: '',
                    fkrk0002: '',
                    fkrk0003: '',
                    fkrk0004: '',
                    fkrk0005: '',
                    fkrk0006: '',
                    fkrk0008: '',
                },
                modalShow: false,
                // 初始化信息总条数
                dataCount: 0,
                // 每页显示多少条
                pageSize: 10,
                columns1: [
                    {
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '区县（市）',
                        align: 'center',
                        key: 'fkrk0003'
                    },
                    {
                        title: '乡镇（街道）',
                        align: 'center',
                        key: 'fkrk0004'
                    },
                    {
                        title: '社区（村）',
                        align: 'center',
                        width: '180',
                        key: 'fkrk0005'
                    },
                    {
                        title: '姓名',
                        key: 'fkrk0006',
                        align: 'center',
                    },
                    {
                        title: '身份证号码',
                        align: 'center',
                        key: 'fkrk0008',
                        width: '200'
                    },
                    {
                        title: '性别',
                        align: 'center',
                        key: 'fkrk0007',
                    },
                    {
                        title: '出生日期',
                        align: 'center',
                        key: 'fkrk0009',
                    }
                    , {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        slot: 'action',
                        className: 'nopadding',
                        width: '200',
                    }
                ],
                data: []
            }
        },
        methods: {
            test() {
                //TODO 测试
                console.log("=============test doSs18900BetaCheck =============");
                var dataParam = {}
                postAction('/api/ac/subsistence/ss00005Service/createSs18900BetaCheck', dataParam).then((res) => {
                })
            },
            handleSuccess(res, file) {
                if (res.errcode === 0) {
                    if (res.data.errorcode === 0) {
                        this.$refs.upload.clearFiles();
                        this.dialoLead = false;
                        this.$Message.success("数据导入成功！");
                        this.getDataList(1);
                    } else {
                        this.$Message.error(res.data.msg);
                        this.$refs.upload.clearFiles()
                    }

                }

            },
            handleError(error, file) {
                this.$Message.error("数据导入失败！")
            },
            showMsgFromChind(data) {
                //自定义子组件回调父组件函数
                // this.searchInfo.fkrk0001 = data;
                // alert("this.searchInfo.fkrk0001:"+this.searchInfo.fkrk0001);
            },
            searchData(index) {
                if (this.searchInfo.bindLevel != '') {
                    if (this.searchInfo.bindLevel === '1') {
                        this.searchInfo.fkrk0003 = this.searchInfo.bindData;
                        this.searchInfo.fkrk0004 = '';
                        this.searchInfo.fkrk0005 = '';
                    } else if (this.searchInfo.bindLevel === '2') {
                        let jdCode = this.searchInfo.bindData;
                        let xqCode = jdCode.substr(0, 6) + "000000";
                        this.searchInfo.fkrk0003 = xqCode;
                        this.searchInfo.fkrk0004 = jdCode;
                        this.searchInfo.fkrk0005 = '';
                    } else if (this.searchInfo.bindLevel === '3') {
                        let sqCode = this.searchInfo.bindData;
                        let jdCode = sqCode.substr(0, 9) + "000";
                        let xqCode = sqCode.substr(0, 6) + "000000";
                        this.searchInfo.fkrk0003 = xqCode;
                        this.searchInfo.fkrk0004 = jdCode;
                        this.searchInfo.fkrk0005 = sqCode;
                    }
                }
                this.getDataList(1)
            },
            // 删除
            remove(item) {
                if (confirm('确定删除该条数据吗')) {
                    var dataParam = {
                        id: item.id
                    }
                    postAction('/api/ac/subsistence/ss00013Service/delete', dataParam).then((res) => {
                        this.getDataList(1)
                        this.$Notice.success({title: '删除成功', desc: ''})
                        this.modalShow = false
                    }).finally(() => {

                    })
                }
            },
            closeModel() {
                this.modalShow = false
            },
            //新增扶贫人口保存事件
            addOk(name) {
                this.initXzqh();
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let dataParam = {
                            fkrk0003: this.formItem.fkrk0003,
                            fkrk0004: this.formItem.fkrk0004,
                            fkrk0005: this.formItem.fkrk0005,
                            fkrk0006: this.formItem.fkrk0006,
                            fkrk0007: this.formItem.fkrk0007,
                            fkrk0008: this.formItem.fkrk0008,
                            fkrk0009: this.formItem.fkrk0009,
                        }
                        postAction('/api/ac/subsistence/ss00013Service/insert', dataParam).then((res) => {
                            if (res.data.data.errcode === 0) {
                                this.modalShow = false
                                this.$Message.success("新增成功！")
                                this.getDataList(1)
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '请输入不为空的项!', desc: '请输入不为空的项!'})
                    }
                });

            },
            updateOk(name) {
                this.initXzqh();
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let dataParam = {
                            id: this.formItem.id,
                            fkrk0001: this.formItem.fkrk0001,
                            fkrk0003: this.formItem.fkrk0003,
                            fkrk0004: this.formItem.fkrk0004,
                            fkrk0005: this.formItem.fkrk0005,
                            fkrk0006: this.formItem.fkrk0006,
                            fkrk0007: this.formItem.fkrk0007,
                            fkrk0008: this.formItem.fkrk0008,
                            fkrk0009: this.formItem.fkrk0009,
                        }
                        postAction('/api/ac/subsistence/ss00013Service/update', dataParam).then((res) => {
                            if (res.data.data.errcode === 0) {
                                this.modalShow = false
                                this.$Message.success("编辑成功！")
                                this.getDataList(1)
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '请输入不为空的项!', desc: '请输入不为空的项!'})
                    }
                });

            },
            initXzqh() {
                if (this.formItem.bindLevel != '') {
                    if (this.formItem.bindLevel === '1') {
                        this.formItem.fkrk0003 = this.formItem.bindData;
                        this.formItem.fkrk0004 = '';
                        this.formItem.fkrk0005 = '';
                    } else if (this.formItem.bindLevel === '2') {
                        let jdCode = this.formItem.bindData;
                        let xqCode = jdCode.substr(0, 6) + "000000";
                        this.formItem.fkrk0003 = xqCode;
                        this.formItem.fkrk0004 = jdCode;
                        this.formItem.fkrk0005 = '';
                    } else if (this.formItem.bindLevel === '3') {
                        let sqCode = this.formItem.bindData;
                        let jdCode = sqCode.substr(0, 9) + "000";
                        let xqCode = sqCode.substr(0, 6) + "000000";
                        this.formItem.fkrk0003 = xqCode;
                        this.formItem.fkrk0004 = jdCode;
                        this.formItem.fkrk0005 = sqCode;
                    }
                }
            },
            //新增扶贫人口事件
            createSS00013() {
                this.xq_disabled = false;
                this.jd_disabled = false;
                this.sq_disabled = false;
                this.modalShow = true
                this.sel_xqval = '',
                    this.sel_jdval = '',
                    this.sel_sqval = '',
                    this.formItem.id = ''
                this.formItem.fkrk0010 = '',
                    this.sel_xqval = '',
                    this.sel_jdval = '',
                    this.sel_sqval = '',
                    this.formItem.fkrk0002 = ''
                this.formItem.fkrk0003 = ''
                this.formItem.fkrk0004 = ''
                this.formItem.fkrk0005 = ''
                this.formItem.fkrk0006 = ''
                this.formItem.fkrk0007 = ''
                this.formItem.fkrk0008 = ''
                this.formItem.fkrk0009 = ''
                this.type = '1'
                this.title = '新增'
                this.disable = false
            },
            showModal(row) {
                this.xq_disabled = true;
                this.jd_disabled = true;
                this.sq_disabled = true;
                this.modalShow = true
                this.type = '3'
                this.title = '详情'
                this.sel_xqval = row.fkrk0013,
                    this.sel_jdval = row.fkrk0014,
                    this.sel_sqval = row.fkrk0015,
                    this.formItem = row
                this.disable = true
            },
            updateModal(row) {
                this.xq_disabled = false;
                this.jd_disabled = false;
                this.sq_disabled = false;
                this.modalShow = true
                this.formItem.bindData = '';
                this.formItem.bindLevel = '';
                this.sel_xqval = row.fkrk0013,
                    this.sel_jdval = row.fkrk0014,
                    this.sel_sqval = row.fkrk0015,
                    this.type = '2'
                this.title = '修改'
                this.formItem = row
                this.formItem.fkrk0003 = row.fkrk0003;
                this.formItem.fkrk0004 = row.fkrk0004;
                this.formItem.fkrk0005 = row.fkrk0005;
                this.disable = false
            },
            //获取数据
            getDataList(pageNo) {
                var param = {
                    'request_map': {
                        'pageSize': 10,
                        'pageNo': pageNo,
                        'sort': '',
                        'order': '',
                        'fkrk0003': this.searchInfo.fkrk0003,
                        'fkrk0004': this.searchInfo.fkrk0004,
                        'fkrk0005': this.searchInfo.fkrk0005,
                        'fkrk0006': this.searchInfo.fkrk0006,
                        'fkrk0008': this.searchInfo.fkrk0008,
                    }
                }
                var that = this;
                postAction('/api/ac/subsistence/ss00013Service/list', param).then((res) => {
                    that.data = res.data.data.data;
                    that.dataCount = res.data.data.total;
                }).finally(() => {

                })
            },
            changePage(pageNo) {
                //页面翻页事件
                this.data = this.getDataList(pageNo);
            }
        },
        created() {
            // 默认请求第一页列表
            this.getDataList(1)
        }

    }
</script>

<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }
</style>
